home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Online / Apache / lib / php / Date / Calc.php
Encoding:
PHP Script  |  2001-03-06  |  43.9 KB  |  1,505 lines

  1. <?php
  2.  
  3. // The constant telling us what day starts the week. Monday (1) is the
  4. // international standard. Redefine this to 0 if you want weeks to
  5. // begin on Sunday.
  6. define('DATE_CALC_BEGIN_WEEKDAY', 1);
  7.  
  8. /**
  9.  * Date_Calc is a calendar class used to calculate and
  10.  * manipulate calendar dates and retrieve dates in a calendar
  11.  * format. It does not rely on 32-bit system date stamps, so
  12.  * you can display calendars and compare dates that date
  13.  * pre 1970 and post 2038.
  14.  *
  15.  * This source file is subject to version 2.02 of the PHP license,
  16.  * that is bundled with this package in the file LICENSE, and is
  17.  * available at through the world-wide-web at
  18.  * http://www.php.net/license/2_02.txt.
  19.  * If you did not receive a copy of the PHP license and are unable to
  20.  * obtain it through the world-wide-web, please send a note to
  21.  * license@php.net so we can mail you a copy immediately.
  22.  *
  23.  * Copyright (c) 1999, 2000 ispi
  24.  *
  25.  * @access public
  26.  *
  27.  * @version 1.2.2
  28.  * @author Monte Ohrt <monte@ispi.net>
  29.  */
  30.  
  31. class Date_Calc {
  32.  
  33.     /**
  34.      * Returns the current local date. NOTE: This function
  35.      * retrieves the local date using strftime(), which may
  36.      * or may not be 32-bit safe on your system.
  37.      *
  38.      * @param string the strftime() format to return the date
  39.      *
  40.      * @access public
  41.      *
  42.      * @return string the current date in specified format
  43.      */
  44.  
  45.     function dateNow($format="%Y%m%d")
  46.     {
  47.         return(strftime($format,time()));    
  48.  
  49.     } // end func dateNow
  50.      
  51.      /**
  52.      * Returns true for valid date, false for invalid date.
  53.      *
  54.      * @param string year in format CCYY
  55.      * @param string month in format MM
  56.      * @param string day in format DD
  57.      *
  58.      * @access public
  59.      *
  60.      * @return boolean true/false
  61.      */
  62.  
  63.     function isValidDate($day, $month, $year)
  64.     {
  65.  
  66.         if(empty($year) || empty($month) || empty($day))
  67.             return false;
  68.         
  69.         // must be digits only
  70.         if(preg_match("/\D/",$year))
  71.             return false;
  72.         if(preg_match("/\D/",$month))
  73.             return false;
  74.         if(preg_match("/\D/",$day))
  75.             return false;
  76.  
  77.         if($year < 0 || $year > 9999)
  78.             return false;                        
  79.         if($month < 1 || $month > 12)
  80.             return false;
  81.         if($day < 1 || $day > 31 || $day > Date_Calc::daysInMonth($month,$year))
  82.             return false;
  83.                         
  84.         return true;
  85.  
  86.     } // end func isValidDate    
  87.         
  88.     function isLeapYear($year="")
  89.     {
  90.     
  91.         if(empty($year))
  92.             $year = Date_Calc::dateNow("%Y");
  93.  
  94.         if(strlen($year) != 4)
  95.             return false;
  96.         
  97.         if(preg_match("/\D/",$year))
  98.             return false;
  99.         
  100.         return (($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0);
  101.  
  102.     } // end func isLeapYear
  103.         
  104.     /**
  105.      * Determines if given date is a future date from now.
  106.      *
  107.      * @param string year in format CCYY
  108.      * @param string month in format MM
  109.      * @param string day in format DD
  110.      *
  111.      * @access public
  112.      *
  113.      * @return boolean true/false
  114.      */
  115.  
  116.     function isFutureDate($day,$month,$year)
  117.     {
  118.         $this_year = Date_Calc::dateNow("%Y");
  119.         $this_month = Date_Calc::dateNow("%m");
  120.         $this_day = Date_Calc::dateNow("%d");
  121.         
  122.         
  123.         if($year > $this_year)
  124.             return true;
  125.         elseif($year == $this_year)
  126.             if($month > $this_month)
  127.                 return true;
  128.             elseif($month == $this_month)
  129.                 if($day > $this_day)
  130.                     return true;
  131.  
  132.         return false;
  133.  
  134.     } // end func isFutureDate
  135.     
  136.     /**
  137.      * Determines if given date is a past date from now.
  138.      *
  139.      * @param string year in format CCYY
  140.      * @param string month in format MM
  141.      * @param string day in format DD
  142.      *
  143.      * @access public
  144.      *
  145.      * @return boolean true/false
  146.      */
  147.  
  148.     function isPastDate($day,$month,$year)
  149.     {
  150.         $this_year = Date_Calc::dateNow("%Y");
  151.         $this_month = Date_Calc::dateNow("%m");
  152.         $this_day = Date_Calc::dateNow("%d");
  153.         
  154.         
  155.         if($year < $this_year)
  156.             return true;
  157.         elseif($year == $this_year)
  158.             if($month < $this_month)
  159.                 return true;
  160.             elseif($month == $this_month)
  161.                 if($day < $this_day)
  162.                     return true;
  163.  
  164.         return false;
  165.  
  166.     } // end func isPastDate
  167.  
  168.     /**
  169.      * Returns day of week for given date, 0=Sunday
  170.      *
  171.      * @param string year in format CCYY, default is current local year
  172.      * @param string month in format MM, default is current local month
  173.      * @param string day in format DD, default is current local day
  174.      *
  175.      * @access public
  176.      *
  177.      * @return int $weekday_number
  178.      */
  179.  
  180.     function dayOfWeek($day="",$month="",$year="")
  181.     {
  182.         
  183.         if(empty($year))
  184.             $year = Date_Calc::dateNow("%Y");
  185.         if(empty($month))
  186.             $month = Date_Calc::dateNow("%m");
  187.         if(empty($day))
  188.             $day = Date_Calc::dateNow("%d");
  189.         
  190.         if($month > 2)
  191.             $month -= 2;
  192.         else
  193.         {
  194.             $month += 10;
  195.             $year--;
  196.         }
  197.         
  198.         $day =     ( floor((13 * $month - 1) / 5) +
  199.                 $day + ($year % 100) +
  200.                 floor(($year % 100) / 4) +
  201.                 floor(($year / 100) / 4) - 2 *
  202.                 floor($year / 100) + 77);
  203.         
  204.         $weekday_number = (($day - 7 * floor($day / 7)));
  205.         
  206.         return $weekday_number;
  207.         
  208.     } // end func dayOfWeek
  209.     
  210.     /**
  211.      * Returns week of the year, first Sunday is first day of first week
  212.      *
  213.      * @param string year in format CCYY
  214.      * @param string month in format MM
  215.      * @param string day in format DD
  216.      *
  217.      * @access public
  218.      *
  219.      * @return integer $week_number
  220.      */
  221.  
  222.     function weekOfYear($day,$month,$year)
  223.     {
  224.         if(empty($year))
  225.             $year = Date_Calc::dateNow("%Y");
  226.         if(empty($month))
  227.             $month = Date_Calc::dateNow("%m");
  228.         if(empty($day))
  229.             $day = Date_Calc::dateNow("%d");
  230.  
  231.         $week_year = $year - 1501;
  232.         $week_day = $week_year * 365 + floor($week_year / 4) - 29872 + 1
  233.                 - floor($week_year / 100) + floor(($week_year - 300) / 400);
  234.          
  235.         $week_number =
  236.                 floor((Date_Calc::julianDate($day,$month,$year) + floor(($week_day + 4) % 7)) / 7);
  237.                    
  238.         return $week_number;
  239.  
  240.     } // end func weekOfYear
  241.     
  242.     /**
  243.      * Returns number of days since 31 December of year before given date.
  244.      *
  245.      * @param string year in format CCYY, default is current local year
  246.      * @param string month in format MM, default is current local month
  247.      * @param string day in format DD, default is current local day
  248.      *
  249.      * @access public
  250.      *
  251.      * @return int $julian
  252.      */
  253.  
  254.     function julianDate($day="",$month="",$year="")
  255.     {
  256.         if(empty($year))
  257.             $year = Date_Calc::dateNow("%Y");
  258.         if(empty($month))
  259.             $month = Date_Calc::dateNow("%m");
  260.         if(empty($day))
  261.             $day = Date_Calc::dateNow("%d");
  262.  
  263.         $days = array(0,31,59,90,120,151,181,212,243,273,304,334);
  264.         
  265.         $julian = ($days[$month - 1] + $day);
  266.  
  267.         if($month > 2 && Date_Calc::isLeapYear($year))
  268.             $julian++;
  269.         
  270.         return($julian);
  271.  
  272.     } // end func julianDate
  273.  
  274.     /**
  275.      * Returns quarter of the year for given date
  276.      *
  277.      * @param string year in format CCYY, default current local year
  278.      * @param string month in format MM, default current local month
  279.      * @param string day in format DD, default current local day
  280.      *
  281.      * @access public
  282.      *
  283.      * @return int $year_quarter
  284.      */
  285.  
  286.     function quarterOfYear($day="",$month="",$year="")
  287.     {
  288.         if(empty($year))
  289.             $year = Date_Calc::dateNow("%Y");
  290.         if(empty($month))
  291.             $month = Date_Calc::dateNow("%m");
  292.         if(empty($day))
  293.             $day = Date_Calc::dateNow("%d");
  294.  
  295.         $year_quarter = (intval(($month - 1) / 3 + 1));
  296.         
  297.         return $year_quarter;
  298.  
  299.     } // end func quarterOfYear
  300.  
  301.     /**
  302.      * Returns date of begin of next month of given date.
  303.      *
  304.      * @param string year in format CCYY, default current local year
  305.      * @param string month in format MM, default current local month
  306.      * @param string day in format DD, default current local day
  307.      * @param string format for returned date
  308.      *
  309.      * @access public
  310.      *
  311.      * @return string date in given format
  312.      */
  313.  
  314.     function beginOfNextMonth($day="",$month="",$year="",$format="%Y%m%d")
  315.     {
  316.         if(empty($year))
  317.             $year = Date_Calc::dateNow("%Y");
  318.         if(empty($month))
  319.             $month = Date_Calc::dateNow("%m");
  320.         if(empty($day))
  321.             $day = Date_Calc::dateNow("%d");
  322.  
  323.         if($month < 12)
  324.         {
  325.             $month++;
  326.             $day=1;
  327.         }
  328.         else
  329.         {
  330.             $year++;
  331.             $month=1;
  332.             $day=1;
  333.         }        
  334.                 
  335.         return Date_Calc::dateFormat($day,$month,$year,$format);
  336.  
  337.     } // end func beginOfNextMonth
  338.  
  339.     /**
  340.      * Returns date of the last day of next month of given date.
  341.      *
  342.      * @param string year in format CCYY, default current local year
  343.      * @param string month in format MM, default current local month
  344.      * @param string day in format DD, default current local day
  345.      * @param string format for returned date
  346.      *
  347.      * @access public
  348.      *
  349.      * @return string date in given format
  350.      */
  351.  
  352.     function endOfNextMonth($day="",$month="",$year="",$format="%Y%m%d")
  353.     {
  354.         if(empty($year))
  355.             $year = Date_Calc::dateNow("%Y");
  356.         if(empty($month))
  357.             $month = Date_Calc::dateNow("%m");
  358.         if(empty($day))
  359.             $day = Date_Calc::dateNow("%d");
  360.  
  361.         
  362.         if($month < 12)
  363.         {
  364.             $month++;
  365.         }
  366.         else
  367.         {
  368.             $year++;
  369.             $month=1;
  370.         }        
  371.  
  372.         $day = Date_Calc::daysInMonth($month,$year);
  373.  
  374.         return Date_Calc::dateFormat($day,$month,$year,$format);
  375.  
  376.     } // end func endOfNextMonth
  377.  
  378.     /**
  379.      * Returns date of the first day of previous month of given date.
  380.      *
  381.      * @param string year in format CCYY, default current local year
  382.      * @param string month in format MM, default current local month
  383.      * @param string day in format DD, default current local day
  384.      * @param string format for returned date
  385.      *
  386.      * @access public
  387.      *
  388.      * @return string date in given format
  389.      */
  390.  
  391.     function beginOfPrevMonth($day="",$month="",$year="",$format="%Y%m%d")
  392.     {
  393.         if(empty($year))
  394.             $year = Date_Calc::dateNow("%Y");
  395.         if(empty($month))
  396.             $month = Date_Calc::dateNow("%m");
  397.         if(empty($day))
  398.             $day = Date_Calc::dateNow("%d");
  399.  
  400.         if($month > 1)
  401.         {
  402.             $month--;
  403.             $day=1;
  404.         }
  405.         else
  406.         {
  407.             $year--;
  408.             $month=12;
  409.             $day=1;
  410.         }        
  411.         
  412.         return Date_Calc::dateFormat($day,$month,$year,$format);
  413.         
  414.     } // end func beginOfPrevMonth
  415.         
  416.     /**
  417.      * Returns date of the last day of previous month for given date.
  418.      *
  419.      * @param string year in format CCYY, default current local year
  420.      * @param string month in format MM, default current local month
  421.      * @param string day in format DD, default current local day
  422.      * @param string format for returned date
  423.      *
  424.      * @access public
  425.      *
  426.      * @return string date in given format
  427.      */
  428.  
  429.     function endOfPrevMonth($day="",$month="",$year="",$format="%Y%m%d")
  430.     {
  431.         if(empty($year))
  432.             $year = Date_Calc::dateNow("%Y");
  433.         if(empty($month))
  434.             $month = Date_Calc::dateNow("%m");
  435.         if(empty($day))
  436.             $day = Date_Calc::dateNow("%d");
  437.  
  438.         if($month > 1)
  439.         {
  440.             $month--;
  441.         }
  442.         else
  443.         {
  444.             $year--;
  445.             $month=12;
  446.         }        
  447.  
  448.         $day = Date_Calc::daysInMonth($month,$year);
  449.  
  450.         return Date_Calc::dateFormat($day,$month,$year,$format);    
  451.  
  452.     } // end func endOfPrevMonth
  453.  
  454.     /**
  455.      * Returns date of the next weekday of given date,
  456.      * skipping from Friday to Monday.
  457.      *
  458.      * @param string year in format CCYY, default current local year
  459.      * @param string month in format MM, default current local month
  460.      * @param string day in format DD, default current local day
  461.      * @param string format for returned date
  462.      *
  463.      * @access public
  464.      *
  465.      * @return string date in given format
  466.      */
  467.  
  468.     function nextWeekday($day="",$month="",$year="",$format="%Y%m%d")
  469.     {
  470.         if(empty($year))
  471.             $year = Date_Calc::dateNow("%Y");
  472.         if(empty($month))
  473.             $month = Date_Calc::dateNow("%m");
  474.         if(empty($day))
  475.             $day = Date_Calc::dateNow("%d");
  476.  
  477.         $days = Date_Calc::dateToDays($day,$month,$year);
  478.         
  479.         if(Date_Calc::dayOfWeek($day,$month,$year) == 5)
  480.             $days += 3;
  481.         elseif(Date_Calc::dayOfWeek($day,$month,$year) == 6)
  482.             $days += 2;
  483.         else
  484.             $days += 1;
  485.             
  486.         return(Date_Calc::daysToDate($days,$format));
  487.  
  488.     } // end func nextWeekday
  489.  
  490.     /**
  491.      * Returns date of the previous weekday,
  492.      * skipping from Monday to Friday.
  493.      *
  494.      * @param string year in format CCYY, default current local year
  495.      * @param string month in format MM, default current local month
  496.      * @param string day in format DD, default current local day
  497.      * @param string format for returned date
  498.      *
  499.      * @access public
  500.      *
  501.      * @return string date in given format
  502.      */
  503.  
  504.     function prevWeekday($day="",$month="",$year="",$format="%Y%m%d")
  505.     {
  506.         if(empty($year))
  507.             $year = Date_Calc::dateNow("%Y");
  508.         if(empty($month))
  509.             $month = Date_Calc::dateNow("%m");
  510.         if(empty($day))
  511.             $day = Date_Calc::dateNow("%d");
  512.  
  513.         $days = Date_Calc::dateToDays($day,$month,$year);
  514.  
  515.         if(Date_Calc::dayOfWeek($day,$month,$year) == 1)
  516.             $days -= 3;
  517.         elseif(Date_Calc::dayOfWeek($day,$month,$year) == 0)
  518.             $days -= 2;
  519.         else
  520.             $days -= 1;
  521.             
  522.         return(Date_Calc::daysToDate($days,$format));
  523.  
  524.     } // end func prevWeekday
  525.  
  526.     /**
  527.      * Returns date of the next specific day of the week
  528.      * from the given date.
  529.      *
  530.      * @param int day of week, 0=Sunday
  531.      * @param string year in format CCYY, default current local year
  532.      * @param string month in format MM, default current local month
  533.      * @param string day in format DD, default current local day
  534.      * @param boolean onOrAfter if true and days are same, returns current day
  535.      * @param string format for returned date
  536.      *
  537.      * @access public
  538.      *
  539.      * @return string date in given format
  540.      */
  541.  
  542.     function nextDayOfWeek($dow,$day="",$month="",$year="",$format="%Y%m%d",$onOrAfter=false)
  543.     {
  544.         if(empty($year))
  545.             $year = Date_Calc::dateNow("%Y");
  546.         if(empty($month))
  547.             $month = Date_Calc::dateNow("%m");
  548.         if(empty($day))
  549.             $day = Date_Calc::dateNow("%d");
  550.  
  551.         $days = Date_Calc::dateToDays($day,$month,$year);
  552.         $curr_weekday = Date_Calc::dayOfWeek($day,$month,$year);
  553.         
  554.         if($curr_weekday == $dow)
  555.         {
  556.             if(!$onOrAfter)
  557.                 $days += 7;
  558.         }
  559.         elseif($curr_weekday > $dow)
  560.             $days += 7 - ( $curr_weekday - $dow );
  561.         else
  562.             $days += $dow - $curr_weekday;
  563.             
  564.         return(Date_Calc::daysToDate($days,$format));
  565.  
  566.     } // end func nextDayOfWeek
  567.  
  568.     /**
  569.      * Returns date of the previous specific day of the week
  570.      * from the given date.
  571.      *
  572.      * @param int day of week, 0=Sunday
  573.      * @param string year in format CCYY, default current local year
  574.      * @param string month in format MM, default current local month
  575.      * @param string day in format DD, default current local day
  576.      * @param boolean onOrBefore if true and days are same, returns current day
  577.      * @param string format for returned date
  578.      *
  579.      * @access public
  580.      *
  581.      * @return string date in given format
  582.      */
  583.  
  584.     function prevDayOfWeek($dow,$day="",$month="",$year="",$format="%Y%m%d",$onOrBefore=false)
  585.     {
  586.         if(empty($year))
  587.             $year = Date_Calc::dateNow("%Y");
  588.         if(empty($month))
  589.             $month = Date_Calc::dateNow("%m");
  590.         if(empty($day))
  591.             $day = Date_Calc::dateNow("%d");
  592.  
  593.         $days = Date_Calc::dateToDays($day,$month,$year);
  594.         $curr_weekday = Date_Calc::dayOfWeek($day,$month,$year);
  595.         
  596.         if($curr_weekday == $dow)
  597.         {
  598.             if(!$onOrBefore)
  599.                 $days -= 7;
  600.         }
  601.         elseif($curr_weekday < $dow)
  602.             $days -= 7 - ( $dow - $curr_weekday );
  603.         else
  604.             $days -= $curr_weekday - $dow;
  605.             
  606.         return(Date_Calc::daysToDate($days,$format));
  607.  
  608.     } // end func prevDayOfWeek    
  609.  
  610.     /**
  611.      * Returns date of the next specific day of the week
  612.      * on or before the given date.
  613.      *
  614.      * @param int day of week, 0=Sunday
  615.      * @param string year in format CCYY, default current local year
  616.      * @param string month in format MM, default current local month
  617.      * @param string day in format DD, default current local day
  618.      * @param string format for returned date
  619.      *
  620.      * @access public
  621.      *
  622.      * @return string date in given format
  623.      */
  624.  
  625.     function nextDayOfWeekOnOrAfter($dow,$day="",$month="",$year="",$format="%Y%m%d")
  626.     {
  627.         return(Date_Calc::nextDayOfWeek($dow,$day="",$month="",$year="",$format="%Y%m%d",true));
  628.     } // end func nextDayOfWeekOnOrAfter
  629.  
  630.     /**
  631.      * Returns date of the previous specific day of the week
  632.      * on or before the given date.
  633.      *
  634.      * @param int day of week, 0=Sunday
  635.      * @param string year in format CCYY, default current local year
  636.      * @param string month in format MM, default current local month
  637.      * @param string day in format DD, default current local day
  638.      * @param string format for returned date
  639.      *
  640.      * @access public
  641.      *
  642.      * @return string date in given format
  643.      */
  644.  
  645.     function prevDayOfWeekOnOrBefore($dow,$day="",$month="",$year="",$format="%Y%m%d")
  646.     {
  647.         return(Date_Calc::prevDayOfWeek($dow,$day="",$month="",$year="",$format="%Y%m%d",true));
  648.  
  649.     } // end func prevDayOfWeekOnOrAfter        
  650.                 
  651.     /**
  652.      * Returns date of day after given date.
  653.      *
  654.      * @param string year in format CCYY, default current local year
  655.      * @param string month in format MM, default current local month
  656.      * @param string day in format DD, default current local day
  657.      * @param string format for returned date
  658.      *
  659.      * @access public
  660.      *
  661.      * @return string date in given format
  662.      */
  663.  
  664.     function nextDay($day="",$month="",$year="",$format="%Y%m%d")
  665.     {
  666.         if(empty($year))
  667.             $year = Date_Calc::dateNow("%Y");
  668.         if(empty($month))
  669.             $month = Date_Calc::dateNow("%m");
  670.         if(empty($day))
  671.             $day = Date_Calc::dateNow("%d");
  672.  
  673.         $days = Date_Calc::dateToDays($day,$month,$year);
  674.             
  675.         return(Date_Calc::daysToDate($days + 1,$format));
  676.  
  677.     } // end func nextDay
  678.     
  679.     /**
  680.      * Returns date of day before given date.
  681.      *
  682.      * @param string year in format CCYY, default current local year
  683.      * @param string month in format MM, default current local month
  684.      * @param string day in format DD, default current local day
  685.      * @param string format for returned date
  686.      *
  687.      * @access public
  688.      *
  689.      * @return string date in given format
  690.      */
  691.  
  692.     function prevDay($day="",$month="",$year="",$format="%Y%m%d")
  693.     {
  694.         if(empty($year))
  695.             $year = Date_Calc::dateNow("%Y");
  696.         if(empty($month))
  697.             $month = Date_Calc::dateNow("%m");
  698.         if(empty($day))
  699.             $day = Date_Calc::dateNow("%d");
  700.  
  701.         $days = Date_Calc::dateToDays($day,$month,$year);
  702.             
  703.         return(Date_Calc::daysToDate($days - 1,$format));
  704.  
  705.     } // end func prevDay
  706.  
  707.     /**
  708.      * Sets century for 2 digit year.
  709.      * 51-99 is 19, else 20
  710.      *
  711.      * @param string 2 digit year
  712.      *
  713.      * @access public
  714.      *
  715.      * @return string 4 digit year
  716.      */
  717.  
  718.     function defaultCentury($year)
  719.     {
  720.         if(strlen($year) == 1)
  721.             $year = "0$year";
  722.         if($year > 50)
  723.             return( "19$year" );
  724.         else
  725.             return( "20$year" );
  726.  
  727.     } // end func defaultCentury
  728.     
  729.     /**
  730.      * Returns number of days between two given dates.
  731.      *
  732.      * @param string year in format CCYY
  733.      * @param string month in format MM
  734.      * @param string day in format DD
  735.      * @param string year in format CCYY
  736.      * @param string month in format MM
  737.      * @param string day in format DD
  738.      *
  739.      * @access public
  740.      *
  741.      * @return int absolute number of days between dates,
  742.      *      -1 if there is an error.
  743.      */
  744.  
  745.     function dateDiff($day1,$month1,$year1,$day2,$month2,$year2)
  746.     {
  747.         if(!Date_Calc::isValidDate($day1,$month1,$year1))
  748.             return -1;
  749.         if(!Date_Calc::isValidDate($day2,$month2,$year2))
  750.             return -1;  
  751.         
  752.         return(abs((Date_Calc::dateToDays($day1,$month1,$year1))
  753.                     - (Date_Calc::dateToDays($day2,$month2,$year2))));
  754.  
  755.     } // end func dateDiff
  756.     
  757.     /**
  758.      * Find the number of days in the given month.
  759.      *
  760.      * @param string month in format MM, default current local month
  761.      *
  762.      * @access public
  763.      *
  764.      * @return int number of days
  765.      */
  766.  
  767.     function daysInMonth($month="",$year="")
  768.     {
  769.         if(empty($year))
  770.             $year = Date_Calc::dateNow("%Y");
  771.         if(empty($month))
  772.             $month = Date_Calc::dateNow("%m");
  773.  
  774.         if($month == 2)
  775.         {
  776.             if(Date_Calc::isLeapYear($year))
  777.                 return 29;
  778.             else
  779.                 return 28;
  780.         }
  781.         elseif($month == 4 or $month == 6 or $month == 9 or $month == 11)
  782.             return 30;
  783.         else
  784.             return 31;
  785.  
  786.     } // end func daysInMonth
  787.  
  788.     /**
  789.      * Returns the number of rows on a calendar month. Useful for
  790.      * determining the number of rows when displaying a typical
  791.      * month calendar.
  792.      *
  793.      * @param string month in format MM, default current local month
  794.      * @param string year in format YYCC, default current local year
  795.      *
  796.      * @access public
  797.      *
  798.      * @return int number of weeks
  799.      */
  800.  
  801.     function weeksInMonth($month="",$year="")
  802.     {
  803.         if(empty($year))
  804.             $year = Date_Calc::dateNow("%Y");
  805.         if(empty($month))
  806.             $month = Date_Calc::dateNow("%m");
  807.  
  808.         return ceil((Date_Calc::daysInMonth($month,$year)+Date_Calc::firstOfMonthWeekday($month,$year) - DATE_CALC_BEGIN_WEEKDAY)/7);
  809.  
  810.     } // end func weeksInMonth    
  811.         
  812.     /**
  813.      * Find the day of the week for the first of the month of given date.
  814.      *
  815.      * @param string year in format CCYY, default to current local year
  816.      * @param string month in format MM, default to current local month
  817.      *
  818.      * @access public
  819.      *
  820.      * @return int number of weekday for the first day, 0=Sunday
  821.      */
  822.  
  823.     function firstOfMonthWeekday($month="",$year="")
  824.     {
  825.         if(empty($year))
  826.             $year = Date_Calc::dateNow("%Y");
  827.         if(empty($month))
  828.             $month = Date_Calc::dateNow("%m");
  829.  
  830.         return(Date_Calc::dayOfWeek("01",$month,$year));
  831.  
  832.     } // end func firstOfMonthWeekday
  833.  
  834.     /**
  835.      * Return date of first day of month of given date.
  836.      *
  837.      * @param string year in format CCYY, default current local year
  838.      * @param string month in format MM, default current local month
  839.      * @param string format for returned date
  840.      *
  841.      * @access public
  842.      *
  843.      * @return string date in given format
  844.      */
  845.  
  846.     function beginOfMonth($month="",$year="",$format="%Y%m%d")
  847.     {
  848.         if(empty($year))
  849.             $year = Date_Calc::dateNow("%Y");
  850.         if(empty($month))
  851.             $month = Date_Calc::dateNow("%m");
  852.  
  853.         return(Date_Calc::dateFormat("01",$month,$year,$format));
  854.  
  855.     } // end of func beginOfMonth
  856.     
  857.     /**
  858.      * Find the month day of the beginning of week for given date,
  859.      * using DATE_CALC_BEGIN_WEEKDAY. (can return weekday of prev month.)
  860.      *
  861.      * @param string year in format CCYY, default current local year
  862.      * @param string month in format MM, default current local month
  863.      * @param string day in format DD, default current local day
  864.      * @param string format for returned date
  865.      *
  866.      * @access public
  867.      *
  868.      * @return string date in given format
  869.      */
  870.  
  871.     function beginOfWeek($day="",$month="",$year="",$format="%Y%m%d")
  872.     {
  873.         if(empty($year))
  874.             $year = Date_Calc::dateNow("%Y");
  875.         if(empty($month))
  876.             $month = Date_Calc::dateNow("%m");
  877.         if(empty($day))
  878.             $day = Date_Calc::dateNow("%d");
  879.  
  880.         $this_weekday = Date_Calc::dayOfWeek($day,$month,$year);
  881.  
  882.         $beginOfWeek = (Date_Calc::dateToDays($day,$month,$year)
  883.             - ($this_weekday - DATE_CALC_BEGIN_WEEKDAY));
  884.  
  885.         return(Date_Calc::daysToDate($beginOfWeek,$format));
  886.  
  887.     } // end of func beginOfWeek
  888.  
  889.     /**
  890.      * Find the month day of the end of week for given date,
  891.      * using DATE_CALC_BEGIN_WEEKDAY. (can return weekday
  892.      * of following month.)
  893.      *
  894.      * @param string year in format CCYY, default current local year
  895.      * @param string month in format MM, default current local month
  896.      * @param string day in format DD, default current local day
  897.      * @param string format for returned date
  898.      *
  899.      * @access public
  900.      *
  901.      * @return string date in given format
  902.      */
  903.  
  904.     function endOfWeek($day="",$month="",$year="",$format="%Y%m%d")
  905.     {
  906.         if(empty($year))
  907.             $year = Date_Calc::dateNow("%Y");
  908.         if(empty($month))
  909.             $month = Date_Calc::dateNow("%m");
  910.         if(empty($day))
  911.             $day = Date_Calc::dateNow("%d");
  912.  
  913.         $this_weekday = Date_Calc::dayOfWeek($day,$month,$year);
  914.  
  915.         $last_dayOfWeek = (Date_Calc::dateToDays($day,$month,$year)
  916.             + (6 - $this_weekday + DATE_CALC_BEGIN_WEEKDAY));
  917.  
  918.         return(Date_Calc::daysToDate($last_dayOfWeek,$format));
  919.  
  920.     } // end func endOfWeek
  921.     
  922.     /**
  923.      * Find the month day of the beginning of week after given date,
  924.      * using DATE_CALC_BEGIN_WEEKDAY. (can return weekday of prev month.)
  925.      *
  926.      * @param string year in format CCYY, default current local year
  927.      * @param string month in format MM, default current local month
  928.      * @param string day in format DD, default current local day
  929.      * @param string format for returned date
  930.      *
  931.      * @access public
  932.      *
  933.      * @return string date in given format
  934.      */
  935.  
  936.     function beginOfNextWeek($day="",$month="",$year="",$format="%Y%m%d")
  937.     {
  938.         if(empty($year))
  939.             $year = Date_Calc::dateNow("%Y");
  940.         if(empty($month))
  941.             $month = Date_Calc::dateNow("%m");
  942.         if(empty($day))
  943.             $day = Date_Calc::dateNow("%d");
  944.  
  945.         $date = Date_Calc::daysToDate(Date_Calc::dateToDays($day+7,$month,$year),"%Y%m%d");
  946.  
  947.         $next_week_year = substr($date,0,4);
  948.         $next_week_month = substr($date,4,2);
  949.         $next_week_day = substr($date,6,2);
  950.         
  951.         $this_weekday = Date_Calc::dayOfWeek($next_week_day,$next_week_month,$next_week_year);
  952.  
  953.         $beginOfWeek = (Date_Calc::dateToDays($next_week_day,$next_week_month,$next_week_year)
  954.             - ($this_weekday - DATE_CALC_BEGIN_WEEKDAY));
  955.  
  956.         return(Date_Calc::daysToDate($beginOfWeek,$format));
  957.  
  958.     } // end func beginOfNextWeek
  959.  
  960.     /**
  961.      * Find the month day of the beginning of week before given date,
  962.      * using DATE_CALC_BEGIN_WEEKDAY. (can return weekday of prev month.)
  963.      *
  964.      * @param string year in format CCYY, default current local year
  965.      * @param string month in format MM, default current local month
  966.      * @param string day in format DD, default current local day
  967.      * @param string format for returned date
  968.      *
  969.      * @access public
  970.      *
  971.      * @return string date in given format
  972.      */
  973.  
  974.     function beginOfPrevWeek($day="",$month="",$year="",$format="%Y%m%d")
  975.     {
  976.         if(empty($year))
  977.             $year = Date_Calc::dateNow("%Y");
  978.         if(empty($month))
  979.             $month = Date_Calc::dateNow("%m");
  980.         if(empty($day))
  981.             $day = Date_Calc::dateNow("%d");
  982.  
  983.         $date = Date_Calc::daysToDate(Date_Calc::dateToDays($day-7,$month,$year),"%Y%m%d");
  984.  
  985.         $next_week_year = substr($date,0,4);
  986.         $next_week_month = substr($date,4,2);
  987.         $next_week_day = substr($date,6,2);
  988.  
  989.         $this_weekday = Date_Calc::dayOfWeek($next_week_day,$next_week_month,$next_week_year);
  990.  
  991.         $beginOfWeek = (Date_Calc::dateToDays($next_week_day,$next_week_month,$next_week_year)
  992.             - ($this_weekday - DATE_CALC_BEGIN_WEEKDAY));
  993.  
  994.         return(Date_Calc::daysToDate($beginOfWeek,$format));
  995.  
  996.     } // end func beginOfPrevWeek
  997.  
  998.     /**
  999.      * Return an array with days in week
  1000.      *
  1001.      * @param string year in format CCYY, default current local year
  1002.      * @param string month in format MM, default current local month
  1003.      * @param string day in format DD, default current local day
  1004.      * @param string format for returned date
  1005.      *
  1006.      * @access public
  1007.      *
  1008.      * @return array $week[$weekday]
  1009.      */
  1010.  
  1011.     function getCalendarWeek($day="",$month="",$year="",$format="%Y%m%d")
  1012.     {
  1013.         if(empty($year))
  1014.             $year = Date_Calc::dateNow("%Y");
  1015.         if(empty($month))
  1016.             $month = Date_Calc::dateNow("%m");
  1017.         if(empty($day))
  1018.             $day = Date_Calc::dateNow("%d");
  1019.  
  1020.         $week_array = array();
  1021.  
  1022.         // date for the column of week
  1023.         $curr_day = (Date_Calc::dateToDays($day,$month,$year)
  1024.             - ((Date_Calc::dayOfWeek($day,$month,$year) - DATE_CALC_BEGIN_WEEKDAY)));
  1025.         
  1026.             for($counter=0; $counter <= 6; $counter++)
  1027.             {
  1028.                 $week_array[$counter] = Date_Calc::daysToDate($curr_day,$format);
  1029.                 $curr_day++;
  1030.             }
  1031.         
  1032.         return $week_array;
  1033.     
  1034.     } // end func getCalendarWeek
  1035.  
  1036.     /**
  1037.      * Return a set of arrays to construct a calendar month for
  1038.      * the given date.
  1039.      *
  1040.      * @param string year in format CCYY, default current local year
  1041.      * @param string month in format MM, default current local month
  1042.      * @param string format for returned date
  1043.      *
  1044.      * @access public
  1045.      *
  1046.      * @return array $month[$row][$col]
  1047.      */
  1048.  
  1049.     function getCalendarMonth($month="",$year="",$format="%Y%m%d")
  1050.     {
  1051.         if(empty($year))
  1052.             $year = Date_Calc::dateNow("%Y");
  1053.         if(empty($month))
  1054.             $month = Date_Calc::dateNow("%m");
  1055.  
  1056.         $month_array = array();
  1057.         
  1058.         // date for the first row, first column of calendar month
  1059.         $curr_day = (Date_Calc::dateToDays("01",$month,$year)
  1060.             - Date_Calc::firstOfMonthWeekday($month,$year) + DATE_CALC_BEGIN_WEEKDAY);
  1061.         
  1062.         // number of days in this month
  1063.         $daysInMonth = Date_Calc::daysInMonth($month,$year);
  1064.         
  1065.         $weeksInMonth = Date_Calc::weeksInMonth($month,$year);
  1066.         for($row_counter=0; $row_counter < $weeksInMonth; $row_counter++)
  1067.         {
  1068.             for($column_counter=0; $column_counter <= 6; $column_counter++)
  1069.             {
  1070.                 $month_array[$row_counter][$column_counter] = Date_Calc::daysToDate($curr_day,$format);
  1071.                 $curr_day++;
  1072.             }
  1073.         }
  1074.         
  1075.         return $month_array;
  1076.     
  1077.     } // end func getCalendarMonth
  1078.    
  1079.     /**
  1080.      * Return a set of arrays to construct a calendar year for
  1081.      * the given date.
  1082.      *
  1083.      * @param string year in format CCYY, default current local year
  1084.      * @param string format for returned date
  1085.      *
  1086.      * @access public
  1087.      *
  1088.      * @return array $year[$month][$row][$col]
  1089.      */
  1090.  
  1091.     function getCalendarYear($year="",$format="%Y%m%d")
  1092.     {
  1093.         if(empty($year))
  1094.             $year = Date_Calc::dateNow("%Y");
  1095.  
  1096.         $year_array = array();
  1097.  
  1098.         for($curr_month=0; $curr_month <=11; $curr_month++)
  1099.         {
  1100.             
  1101.             $year_array[$curr_month] = Date_Calc::getCalendarMonth(sprintf("%02d",$curr_month+1),$year,$format);
  1102.             
  1103.             /* for ($x=0; $x< count($year_array[$curr_month]); $x++)
  1104.             {
  1105.                  for($y=0; $y< count($year_array[$curr_month][$x]); $y++)
  1106.                 {
  1107.                     echo "DEBUG: $x,$y:".$year_array[$curr_month][$x][$y]."<br>\n";
  1108.                 }
  1109.             } */
  1110.         }
  1111.         
  1112.         return $year_array;
  1113.     
  1114.     } // end func getCalendarYear
  1115.     
  1116.     /**
  1117.      * Converts a date to number of days since a
  1118.      * distant unspecified epoch.
  1119.      *
  1120.      * @param string year in format CCYY
  1121.      * @param string month in format MM
  1122.      * @param string day in format DD
  1123.      *
  1124.      * @access public
  1125.      *
  1126.      * @return integer number of days
  1127.      */
  1128.  
  1129.     function dateToDays($day,$month,$year)
  1130.     {
  1131.  
  1132.         $century = substr($year,0,2);
  1133.         $year = substr($year,2,2);
  1134.  
  1135.         if($month > 2)
  1136.             $month -= 3;
  1137.         else
  1138.         {
  1139.             $month += 9;
  1140.             if($year)
  1141.                 $year--;
  1142.             else
  1143.             {
  1144.                 $year = 99;
  1145.                 $century --;
  1146.             }
  1147.         }
  1148.         
  1149.         return ( floor((  146097 * $century)    /  4 ) +
  1150.                 floor(( 1461 * $year)        /  4 ) +
  1151.                 floor(( 153 * $month +  2) /  5 ) +
  1152.                     $day +  1721119);
  1153.  
  1154.     } // end func dateToDays
  1155.     
  1156.     /**
  1157.      * Converts number of days to a distant unspecified epoch.
  1158.      *
  1159.      * @param int number of days
  1160.      * @param string format for returned date
  1161.      *
  1162.      * @access public
  1163.      *
  1164.      * @return string date in specified format
  1165.      */
  1166.  
  1167.     function daysToDate($days,$format="%Y%m%d")
  1168.     {
  1169.  
  1170.         $days         -=     1721119;
  1171.         $century     =    floor(( 4 * $days -  1) /  146097);
  1172.         $days        =    floor(4 * $days - 1 - 146097 * $century);
  1173.         $day        =    floor($days /  4);
  1174.         
  1175.         $year        =    floor(( 4 * $day +  3) /  1461);
  1176.         $day        =    floor(4 * $day +  3 -  1461 * $year);
  1177.         $day        =    floor(($day +  4) /  4);
  1178.         
  1179.         $month        =    floor(( 5 * $day -  3) /  153);
  1180.         $day        =    floor(5 * $day -  3 -  153 * $month);
  1181.         $day        =    floor(($day +  5) /  5);
  1182.         
  1183.         if($month < 10)
  1184.             $month +=3;
  1185.         else
  1186.         {
  1187.             $month -=9;
  1188.             if($year++ == 99)
  1189.             {
  1190.                 $year = 0;
  1191.                 $century++;
  1192.             }
  1193.         }
  1194.         
  1195.         $century = sprintf("%02d",$century);
  1196.         $year = sprintf("%02d",$year);
  1197.         
  1198.         return(Date_Calc::dateFormat($day,$month,$century.$year,$format));
  1199.  
  1200.     } // end func daysToDate
  1201.     
  1202.     /**
  1203.      * Calculates the date of the Nth weekday of the month,
  1204.      * such as the second Saturday of January 2000.
  1205.      *
  1206.      * @param string occurance: 1=first, 2=second, 3=third, etc.
  1207.      * @param string dayOfWeek: 0=Sunday, 1=Monday, etc.
  1208.      * @param string year in format CCYY
  1209.      * @param string month in format MM
  1210.      * @param string format for returned date
  1211.      *
  1212.      * @access public
  1213.      *
  1214.      * @return string date in given format
  1215.      */
  1216.  
  1217.     function NWeekdayOfMonth($occurance,$dayOfWeek,$month,$year,$format="%Y%m%d")    {
  1218.         
  1219.         $year = sprintf("%04d",$year);
  1220.         $month = sprintf("%02d",$month);
  1221.         
  1222.         $DOW1day = sprintf("%02d",(($occurance - 1) * 7 + 1));        
  1223.         $DOW1 = Date_Calc::dayOfWeek($month,$year,$DOW1day);
  1224.         
  1225.         $wdate = ($occurance - 1) * 7 + 1 +
  1226.                 (7 + $dayOfWeek - $DOW1) % 7;
  1227.         
  1228.         if( $wdate > Date_Calc::daysInMonth($month,$year))
  1229.                 return -1;
  1230.         else
  1231.                 return(Date_Calc::dateFormat($month,$year,$wdate,$format));
  1232.         
  1233.     } // end func NWeekdayOfMonth
  1234.  
  1235.     /**
  1236.      *  Formats the date in the given format, much like
  1237.      *  strfmt(). This function is used to alleviate the
  1238.      *  problem with 32-bit numbers for dates pre 1970
  1239.      *  or post 2038, as strfmt() has on most systems.
  1240.      *  Most of the formatting options are compatible.
  1241.      *
  1242.      *  formatting options:
  1243.      *
  1244.      *  %a        abbreviated weekday name (Sun, Mon, Tue)
  1245.      *  %A        full weekday name (Sunday, Monday, Tuesday)
  1246.      *  %b        abbreviated month name (Jan, Feb, Mar)
  1247.      *  %B        full month name (January, February, March)
  1248.      *  %d        day of month (range 00 to 31)
  1249.      *  %e        day of month, single digit (range 0 to 31)
  1250.      *  %E        number of days since unspecified epoch (integer)
  1251.      *             (%E is useful for passing a date in a URL as
  1252.      *             an integer value. Then simply use
  1253.      *             daysToDate() to convert back to a date.)
  1254.      *  %j        day of year (range 001 to 366)
  1255.      *  %m        month as decimal number (range 1 to 12)
  1256.      *  %n        newline character (\n)
  1257.      *  %t        tab character (\t)
  1258.      *  %w        weekday as decimal (0 = Sunday)
  1259.      *  %U        week number of current year, first sunday as first week
  1260.      *  %y        year as decimal (range 00 to 99)
  1261.      *  %Y        year as decimal including century (range 0000 to 9999)
  1262.      *  %%        literal '%'
  1263.      *
  1264.      * @param string year in format CCYY
  1265.      * @param string month in format MM
  1266.      * @param string day in format DD
  1267.      * @param string format for returned date
  1268.      *
  1269.      * @access public
  1270.      *
  1271.      * @return string date in given format
  1272.      */
  1273.  
  1274.     function dateFormat($day,$month,$year,$format)
  1275.     {
  1276.         if(!Date_Calc::isValidDate($day,$month,$year))
  1277.         {
  1278.             $year = Date_Calc::dateNow("%Y");
  1279.             $month = Date_Calc::dateNow("%m");
  1280.             $day = Date_Calc::dateNow("%d");
  1281.         }
  1282.  
  1283.         $output = "";
  1284.         
  1285.         for($strpos = 0; $strpos < strlen($format); $strpos++)
  1286.         {
  1287.             $char = substr($format,$strpos,1);
  1288.             if($char == "%")
  1289.             {
  1290.                 $nextchar = substr($format,$strpos + 1,1);
  1291.                 switch($nextchar)
  1292.                 {
  1293.                     case "a":
  1294.                         $output .= Date_Calc::getWeekdayAbbrname($day,$month,$year);
  1295.                         break;
  1296.                     case "A":
  1297.                         $output .= Date_Calc::getWeekdayFullname($day,$month,$year);
  1298.                         break;
  1299.                     case "b":
  1300.                         $output .= Date_Calc::getMonthAbbrname($month);
  1301.                         break;
  1302.                     case "B":
  1303.                         $output .= Date_Calc::getMonthFullname($month);
  1304.                         break;
  1305.                     case "d":
  1306.                         $output .= sprintf("%02d",$day);
  1307.                         break;
  1308.                     case "e":
  1309.                         $output .= $day;
  1310.                         break;
  1311.                     case "E":
  1312.                         $output .= Date_Calc::dateToDays($day,$month,$year);
  1313.                         break;
  1314.                     case "j":
  1315.                         $output .= Date_Calc::julianDate($day,$month,$year);
  1316.                         break;
  1317.                     case "m":
  1318.                         $output .= sprintf("%02d",$month);
  1319.                         break;
  1320.                     case "n":
  1321.                         $output .= "\n";
  1322.                         break;
  1323.                     case "t":
  1324.                         $output .= "\t";
  1325.                         break;
  1326.                     case "w":
  1327.                         $output .= Date_Calc::dayOfWeek($day,$month,$year);
  1328.                         break;
  1329.                     case "U":
  1330.                         $output .= Date_Calc::weekOfYear($day,$month,$year);
  1331.                         break;
  1332.                     case "y":
  1333.                         $output .= substr($year,2,2);
  1334.                         break;
  1335.                     case "Y":
  1336.                         $output .= $year;
  1337.                         break;
  1338.                     case "%":
  1339.                         $output .= "%";
  1340.                         break;
  1341.                     default:
  1342.                         $output .= $char.$nextchar;
  1343.                 }                    
  1344.                 $strpos++;
  1345.             }
  1346.             else
  1347.             {
  1348.                 $output .= $char;
  1349.             }
  1350.         }
  1351.         return $output;
  1352.     
  1353.     } // end func dateFormat
  1354.  
  1355.     /**
  1356.      * Returns the current local year in format CCYY
  1357.      *
  1358.      * @access public
  1359.      *
  1360.      * @return string year in format CCYY
  1361.      */
  1362.     
  1363.     function getYear()
  1364.     {
  1365.         return Date_Calc::dateNow("%Y");        
  1366.  
  1367.     } // end func getYear
  1368.  
  1369.     /**
  1370.      * Returns the current local month in format MM
  1371.      *
  1372.      * @access public
  1373.      *
  1374.      * @return string month in format MM
  1375.      */    
  1376.         
  1377.     function getMonth()
  1378.     {
  1379.         return Date_Calc::dateNow("%m");        
  1380.  
  1381.     } // end func getMonth
  1382.  
  1383.     /**
  1384.      * Returns the current local day in format DD
  1385.      *
  1386.      * @access public
  1387.      *
  1388.      * @return string day in format DD
  1389.      */    
  1390.     
  1391.     function getDay()
  1392.     {
  1393.         return Date_Calc::dateNow("%d");        
  1394.  
  1395.     } // end func getDay
  1396.  
  1397.     /**
  1398.      * Returns the full month name for the given month
  1399.      *
  1400.      * @param string month in format MM
  1401.      *
  1402.      * @access public
  1403.      *
  1404.      * @return string full month name
  1405.      */    
  1406.     
  1407.     function getMonthFullname($month)
  1408.     {
  1409.         if(empty($month))
  1410.             $month = Date_Calc::dateNow("%m");
  1411.  
  1412.         $month_names = array("January","February","March","April","May","June",
  1413.                     "July","August","September","October","November","December");    
  1414.                     
  1415.         return $month_names[($month - 1)];
  1416.  
  1417.     } // end func getMonthFullname
  1418.  
  1419.     /**
  1420.      * Returns the abbreviated month name for the given month
  1421.      *
  1422.      * @param string month in format MM
  1423.      * @param int optional length of abbreviation, default is 3
  1424.      *
  1425.      * @access public
  1426.      *
  1427.      * @return string abbreviated month name
  1428.      */
  1429.         
  1430.     function getMonthAbbrname($month,$length=3)
  1431.     {
  1432.         if(empty($month))
  1433.             $month = Date_Calc::dateNow("%m");
  1434.  
  1435.         $month_names = array("January","February","March","April","May","June",
  1436.                     "July","August","September","October","November","December");    
  1437.                     
  1438.         return substr($month_names[($month - 1)],0,$length);
  1439.         
  1440.     } // end func getMonthAbbrname
  1441.  
  1442.     /**
  1443.      * Returns the full weekday name for the given date
  1444.      *
  1445.      * @param string year in format CCYY, default current local year
  1446.      * @param string month in format MM, default current local month
  1447.      * @param string day in format DD, default current local day
  1448.      *
  1449.      * @access public
  1450.      *
  1451.      * @return string full month name
  1452.      */    
  1453.     
  1454.     function getWeekdayFullname($day="",$month="",$year="")
  1455.     {
  1456.         if(empty($year))
  1457.             $year = Date_Calc::dateNow("%Y");
  1458.         if(empty($month))
  1459.             $month = Date_Calc::dateNow("%m");
  1460.         if(empty($day))
  1461.             $day = Date_Calc::dateNow("%d");
  1462.  
  1463.         $weekday_names = array("Sunday","Monday","Tuesday",
  1464.                 "Wednesday","Thursday","Friday","Saturday");    
  1465.         $weekday = Date_Calc::dayOfWeek($day,$month,$year);
  1466.                             
  1467.         return $weekday_names[$weekday];
  1468.  
  1469.     } // end func getWeekdayFullname
  1470.  
  1471.     /**
  1472.      * Returns the abbreviated weekday name for the given date
  1473.      *
  1474.      * @param string year in format CCYY, default current local year
  1475.      * @param string month in format MM, default current local month
  1476.      * @param string day in format DD, default current local day
  1477.      * @param int optional length of abbreviation, default is 3
  1478.      *
  1479.      * @access public
  1480.      *
  1481.      * @return string full month name
  1482.      */
  1483.  
  1484.     function getWeekdayAbbrname($day="",$month="",$year="",$length=3)
  1485.     {
  1486.         if(empty($year))
  1487.             $year = Date_Calc::dateNow("%Y");
  1488.         if(empty($month))
  1489.             $month = Date_Calc::dateNow("%m");
  1490.         if(empty($day))
  1491.             $day = Date_Calc::dateNow("%d");
  1492.     
  1493.         $weekday_names = array("Sunday","Monday","Tuesday",
  1494.                 "Wednesday","Thursday","Friday","Saturday");    
  1495.  
  1496.         $weekday = Date_Calc::dayOfWeek($day,$month,$year);
  1497.                             
  1498.         return substr($weekday_names[$weekday],0,$length);
  1499.  
  1500.     } // end func getWeekdayFullname
  1501.     
  1502. } // end class Date_calendar
  1503.  
  1504. ?>
  1505.